//    Copyright (C) Kherty.  All rights reserved.
using System;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    public abstract class TextSpacing : IOfficeXmlSerializableAs
    {
        #region IOfficeXmlSerializableAs Members

        void IOfficeXmlSerializableAs.ReadXmlAs(string name, ReadContext context)
        {
            using (var c = context.Read(name))
            {
                ReadXmlCore(c);
            }
        }

        void IOfficeXmlSerializableAs.WriteXmlAs(string name, WriteContext context)
        {
            using (WriteContext c = context.Write(name))
            {
                WriteXmlCore(c);
            }
        }

        #endregion

        internal static TextSpacing ReadSpacing(string name, ReadContext context)
        {
            if (context.ReaderLocalName != name)
                return null;
            using (var c = context.Read(name))
            {
                switch (c.ReaderLocalName)
                {
                    case "spcPct":
                        TextSpacingInPercent pct = new TextSpacingInPercent();
                        pct.ReadXmlCore(c);
                        return pct;
                    case "spcPts":
                        TextSpacingInPoints _TextSpacingInPoints = new TextSpacingInPoints();
                        _TextSpacingInPoints.ReadXmlCore(c);
                        return _TextSpacingInPoints;
                        //return context.ReadElementAs<TextSpacingInPoints>("spcPts");
                    default:
                        throw new NotSupportedException();
                }
            }
        }

        internal abstract void ReadXmlCore(ReadContext context);

        internal abstract void WriteXmlCore(WriteContext context);
    }
}